package com.example.graphic.model.vo;

import lombok.Data;

/**
 * 通用响应包装类
 */
@Data
public class CommonResponse<T> {
    
    /**
     * 响应状态码
     */
    private Integer code;
    
    /**
     * 响应消息
     */
    private String message;
    
    /**
     * 响应数据
     */
    private T data;
    
    /**
     * 是否成功
     */
    private Boolean success;
    
    public CommonResponse() {
    }
    
    public CommonResponse(Integer code, String message, T data, Boolean success) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.success = success;
    }
    
    public static <T> CommonResponse<T> success(T data) {
        return new CommonResponse<>(200, "操作成功", data, true);
    }
    
    public static <T> CommonResponse<T> success(T data, String message) {
        return new CommonResponse<>(200, message, data, true);
    }
    
    public static <T> CommonResponse<T> error(String message) {
        return new CommonResponse<>(500, message, null, false);
    }
    
    public static <T> CommonResponse<T> error(Integer code, String message) {
        return new CommonResponse<>(code, message, null, false);
    }
}